home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Risc World 3
/
Risc World 3.iso
/
SOFTWARE
/
ISSUE6
/
PD
/
PDF
/
DrawFile
/
h
/
GuiDrawFilePath
< prev
next >
Wrap
Text File
|
2003-02-14
|
6KB
|
150 lines
//--------------------------------------------------------------------------
//
// Copyright (c) 2002, Colin Granville
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or
// without modification, are permitted provided that the following
// conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// * The name Colin Granville may not be used to endorse or promote
// products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
//
//--------------------------------------------------------------------------
#ifndef GuiDrawFilePath_h
#define GuiDrawFilePath_h
#include "GuiDrawFile.h"
class GuiDrawFilePathState
{
public:
enum {OFF = -1};
GuiDrawFilePathState() : reserved(0) {reset();}
void reset();
//**** fill methods ****
void setFillColour(unsigned int colour=OFF) {fillColour=colour;}
unsigned int getFillColour() const {return fillColour;}
enum {NON_ZERO = (0<<6), EVEN_ODD = (1<<6)};
void setWindingRule(int rule=NON_ZERO) {pathStyle= ((pathStyle &~ (1<<6)) | rule);}
int getWindingRule() const {return pathStyle & (1<<6);}
//**** outline methods ****
void setOutlineColour(unsigned int colour=OFF) {outlineColour=colour;}
unsigned int getOutlineColour() const {return outlineColour;}
void setOutlineWidth(size_t width=0) {outlineWidth=width;}
unsigned int getOutlineWidth() const {return outlineWidth;}
void setDashPattern(bool on=0) {pathStyle = ((pathStyle &~ (1<<7)) | (on ? (1<<7):0));}
bool isDashPattern() const {return pathStyle & (1<<7);}
//***** outline joins ****
enum
{
JOIN_MITRED,
JOIN_ROUND,
JOIN_BEVELLED,
JOIN_MASK
};
void setJoin(int n=JOIN_MITRED) {pathStyle = (pathStyle &~ 3) | n;}
int getJoin() const {return pathStyle & (3<<0);}
//***** outline caps *******
enum
{
CAP_BUTT,
CAP_ROUND,
CAP_SQUARE,
CAP_TRIANGLE
};
void setEndCap(int n=CAP_BUTT) {pathStyle= ((pathStyle &~ (3<<2)) | (n<<2));}
int getEndCap() const {return (pathStyle >> 2) & 3;}
void setStartCap(int n=CAP_BUTT) {pathStyle= ((pathStyle &~ (3<<4)) | (n<<4));}
int getStartCap() const {return (pathStyle >> 4) & 3;}
void setCapWidth(size_t wid=0) {capWidth=wid;}
int getCapWidth() const {return capWidth;}
void setCapHeight(size_t ht=0) {capHeight=ht;}
int getCapHeight() const {return capHeight;}
private:
unsigned int fillColour;
unsigned int outlineColour;
size_t outlineWidth;
unsigned char pathStyle;
unsigned char reserved;
unsigned char capWidth;
unsigned char capHeight;
};
class GuiDrawFilePath
{
public:
enum {OBJECT_ID = 2};
GuiDrawFilePath(GuiDrawFile&);
~GuiDrawFilePath();
void point(int x,int y) {
drawfile.put(x);drawfile.put(y);
if (x<ob.bounds.xmin) ob.bounds.xmin=x;
if (x>ob.bounds.xmax) ob.bounds.xmax=x;
if (y<ob.bounds.ymin) ob.bounds.ymin=y;
if (y>ob.bounds.ymax) ob.bounds.ymax=y;
}
void start();
void end(const GuiDrawFilePathState&,bool clip=0);
// if there is a dash pattern dashPattern must follow start and state must have patten flag set
void dashPattern(int start_distance_in_dash,int number_of_elements)
{
drawfile.put(start_distance_in_dash);
drawfile.put(number_of_elements);
}
void dashElement(size_t size) {drawfile.put(size);}
void moveTo() {drawfile.put(2);} // followed by 1 point - opens path
void closeSubPath() {drawfile.put(5);} // followed by 0 points
void bezierTo() {drawfile.put(6);} // followed by 3 points
void drawTo() {drawfile.put(8);} // followed by 1 point
private:
GuiDrawFile& drawfile;
GuiDrawFileGraphicsObject ob;
};
#endif